#include "comm.h"

int main()
{
    int pipefd = open(IPC_PATH, O_WRONLY);
    if (pipefd < 0)
        errno_exit("open");

    char line[NUM] = {0};
    while (true)
    {
        printf("请输入你的消息# ");
        fflush(stdout);
        // fgets -> c -> line结尾自动添加\0
        if (fgets(line, sizeof(line), stdin) != nullptr)
        {
            line[strlen(line) - 1] = '\0'; //去掉fgets读入的换行符
            write(pipefd, line, strlen(line));
        }
        else
            break;
    }
    close(pipefd);
    cout << "client exit!" << endl;
    return 0;
}